package com.suncnpap.library.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

class DateHandle {
    public static void main(String[] args) {
        dataHandle();
    }
    public static void dateHandle(){
        Calendar instance = Calendar.getInstance();
        int year = instance.get(Calendar.YEAR);//获取当系统年份
        int MONTH = instance.get(Calendar.MONTH)+1;//月份,需要加1
        int day = instance.get(Calendar.DAY_OF_WEEK);//日期
        int hour = instance.get(Calendar.HOUR_OF_DAY);//获取小时
        int month = instance.get(Calendar.MINUTE);//获取分钟
        int second = instance.get(Calendar.SECOND);//获取秒数
        System.out.println(year+"-"+MONTH+"-"+day+" "+hour+":"+month+":"+second);
    }

    public static void dataHandle(){
        Calendar instance = Calendar.getInstance();
        Date time = instance.getTime();//获取一个时间对象
        DateFormat format = new SimpleDateFormat("YYYY-MM-dd");
        String format1 = format.format(time);
        System.out.println(format1);
    }
}

